package com.hanson.config;

import com.hanson.aop.WebLogAspect;
import com.hanson.common.constant.Constant;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.util.unit.DataSize;
import org.springframework.web.client.RestTemplate;

import javax.servlet.MultipartConfigElement;

/**
 * @description: 系统配置
 * @classname: SystemConfig
 * @author: Hanson
 * @create: 2020/12/18
 **/
@Configuration
public class SystemConfig {

    //生产环境下注册系统接口操作日志切面对象
    @Profile({Constant.ENVIROMENT_PRO, Constant.ENVIROMENT_TEST})
    @Bean
    public WebLogAspect webLogAspect(){
        return new WebLogAspect();
    }


    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        // 单个数据大小
        factory.setMaxFileSize(DataSize.ofMegabytes(5));
        // 总上传数据大小
        factory.setMaxRequestSize(DataSize.ofMegabytes(10));
        return factory.createMultipartConfig();
    }

    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
}
